package com.huawen.cms.app.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huawen.cms.app.entity.WebConfig;
import com.huawen.cms.app.service.WebConfigService;
import com.huawen.cms.app.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/fontConfig")
@RestController
public class WebConfigController extends BaseController {

	@Autowired
	private WebConfigService frontConfigService;

	@RequestMapping(value = "/getById", method = RequestMethod.GET)
	public WebConfig getById(Long id) {
		WebConfig WebConfig = (WebConfig) frontConfigService.getById(id);
		return WebConfig;
	}

	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public WebConfig insert(@RequestBody WebConfig webConfig) {
		frontConfigService.insert(webConfig);
		return webConfig;
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public WebConfig update(@RequestBody WebConfig webConfig) {
		frontConfigService.update(webConfig);

		//需要重新获取一下 不然为不更新为null的字段仍为null
		webConfig = (WebConfig) frontConfigService.getById(webConfig.getId());

		return webConfig;
	}

	@RequestMapping(value = "/getList", method = RequestMethod.POST)
	public List<WebConfig> getList(@RequestBody WebConfig webConfig) {
		List<WebConfig> list = frontConfigService.getList(webConfig);
		return list;
	}

	@RequestMapping(value = "/getPagerList", method = RequestMethod.POST)
	public PageInfo<WebConfig> getPagerList(@RequestBody WebConfig webConfig) {
		Pager pager = getCurrentPager();
		PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
		List<WebConfig> list = frontConfigService.getList(webConfig);
		PageInfo<WebConfig> pageInfo = new PageInfo<WebConfig>(list);
		return pageInfo;
	}

}
